﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:params="clr-namespace:Elysium.Parameters">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/Elysium;component/Themes/SharedResources.xaml"/>
    </ResourceDictionary.MergedDictionaries>

    <Style x:Key="TabItemHeaderStyle" TargetType="{x:Type ContentControl}">
        <Setter Property="Background" Value="{StaticResource TransparentBrush}"/>
        <Setter Property="BorderBrush" Value="{StaticResource LowlightBrush}"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="Foreground" Value="{StaticResource LowlightBrush}"/>
        <Setter Property="FontSize" Value="{Binding RelativeSource={RelativeSource Self}, Path=(params:General.HeaderFontSize), Mode=OneWay}"/>
        <Setter Property="FontStretch" Value="Medium"/>
        <Setter Property="FontStyle" Value="Normal"/>
        <Setter Property="FontWeight" Value="Normal"/>
        <Setter Property="TextOptions.TextFormattingMode" Value="Display"/>
        <Setter Property="TextOptions.TextRenderingMode" Value="ClearType"/>
        <Setter Property="RenderOptions.ClearTypeHint" Value="Enabled"/>
        <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisualStyle}"/>
        <Setter Property="Focusable" Value="True"/>
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        <Setter Property="VerticalContentAlignment" Value="Stretch"/>
        <Setter Property="Padding" Value="{Binding RelativeSource={RelativeSource Self}, Path=(params:General.BoldPadding), Mode=OneWay}"/>
        <Setter Property="SnapsToDevicePixels" Value="True"/>        
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ContentControl}">                    
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                        <Grid TextBlock.Foreground="{TemplateBinding Foreground}"
                              TextBlock.FontFamily="{TemplateBinding FontFamily}"
                              TextBlock.FontSize="{TemplateBinding FontSize}"
                              TextBlock.FontStretch="{TemplateBinding FontStretch}"
                              TextBlock.FontStyle="{TemplateBinding FontStyle}"
                              TextBlock.FontWeight="{TemplateBinding FontWeight}"
                              TextOptions.TextFormattingMode="{TemplateBinding TextOptions.TextFormattingMode}"
                              TextOptions.TextRenderingMode="{TemplateBinding TextOptions.TextRenderingMode}"
                              RenderOptions.ClearTypeHint="{TemplateBinding RenderOptions.ClearTypeHint}"
                              HorizontalAlignment="Stretch"
                              VerticalAlignment="Stretch">
                            <Rectangle x:Name="Indicator"
                                       Fill="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabItem}}, Path=(params:TabControl.IndicatorBrush)}"
                                       StrokeThickness="0"
                                       Height="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabControl}}, Path=(params:TabControl.IndicatorThickness)}"
                                       HorizontalAlignment="Stretch" VerticalAlignment="Bottom"/>
                            <ContentPresenter Margin="{TemplateBinding Padding}"
                                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                              RecognizesAccessKey="True"/>
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabItem}}, Path=TabStripPlacement}" Value="{x:Static Dock.Bottom}">
                            <Setter TargetName="Indicator" Property="VerticalAlignment" Value="Top"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabItem}}, Path=TabStripPlacement}" Value="{x:Static Dock.Left}">
                            <Setter Property="LayoutTransform">
                                <Setter.Value>
                                    <RotateTransform Angle="-90"/>
                                </Setter.Value>
                            </Setter>
                            <Setter TargetName="Indicator" Property="VerticalAlignment" Value="Bottom"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabItem}}, Path=TabStripPlacement}" Value="{x:Static Dock.Right}">
                            <Setter Property="LayoutTransform">
                                <Setter.Value>
                                    <RotateTransform Angle="90"/>
                                </Setter.Value>
                            </Setter>
                            <Setter TargetName="Indicator" Property="VerticalAlignment" Value="Bottom"/>
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabItem}}, Path=TabStripPlacement}" Value="{x:Static Dock.Left}">
                <Setter Property="TextOptions.TextFormattingMode" Value="Ideal"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabItem}}, Path=TabStripPlacement}" Value="{x:Static Dock.Right}">
                <Setter Property="TextOptions.TextFormattingMode" Value="Ideal"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=FontSize, Mode=OneWay, Converter={StaticResource IsGreaterThanConverter}, ConverterParameter=18}">
                <Setter Property="TextOptions.TextFormattingMode" Value="Ideal"/>
            </DataTrigger>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Foreground" Value="{StaticResource ForegroundBrush}"/>
            </Trigger>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabItem}}, Path=IsSelected}" Value="True">
                <Setter Property="BorderBrush" Value="{StaticResource AccentBrush}"/>
                <Setter Property="Foreground" Value="{StaticResource ForegroundBrush}"/>
            </DataTrigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="BorderBrush" Value="{StaticResource DisabledBrush}"/>
                <Setter Property="Foreground" Value="{StaticResource DisabledBrush}"/>
            </Trigger>
        </Style.Triggers>        
    </Style>
    
    <Style TargetType="{x:Type TabItem}">
        <Setter Property="Background" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabControl}}, Path=Background, Mode=OneWay}"/>
        <Setter Property="BorderBrush" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabControl}}, Path=BorderBrush, Mode=OneWay}"/>
        <Setter Property="BorderThickness" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabControl}}, Path=BorderThickness, Mode=OneWay}"/>
        <Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabControl}}, Path=Foreground, Mode=OneWay}"/>
        <Setter Property="FontSize" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabControl}}, Path=FontSize, Mode=OneWay}"/>
        <Setter Property="FontStretch" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabControl}}, Path=FontStretch, Mode=OneWay}"/>
        <Setter Property="FontStyle" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabControl}}, Path=FontStyle, Mode=OneWay}"/>
        <Setter Property="FontWeight" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabControl}}, Path=FontWeight, Mode=OneWay}"/>
        <Setter Property="TextOptions.TextFormattingMode" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabControl}}, Path=(TextOptions.TextFormattingMode), Mode=OneWay}"/>
        <Setter Property="TextOptions.TextRenderingMode" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabControl}}, Path=(TextOptions.TextRenderingMode), Mode=OneWay}"/>
        <Setter Property="RenderOptions.ClearTypeHint" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabControl}}, Path=(RenderOptions.ClearTypeHint), Mode=OneWay}"/>
        <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisualStyle}"/>
        <Setter Property="Focusable" Value="True"/>
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        <Setter Property="VerticalContentAlignment" Value="Stretch"/>
        <Setter Property="Padding" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabControl}}, Path=Padding, Mode=OneWay}"/>
        <Setter Property="params:TabItem.HeaderStyle" Value="{StaticResource TabItemHeaderStyle}"/>
        <Setter Property="params:TabControl.IndicatorBrush" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabControl}}, Path=(params:TabControl.IndicatorBrush)}"/>
        <!-- Temporary removed to fix bugs 1144, 1174, 1216 -->
        <!--<Setter Property="OverridesDefaultStyle" Value="True"/>-->
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TabItem}">
                    <ContentControl x:Name="ContentHost"
                                    Content="{TemplateBinding Header}"
                                    TextOptions.TextFormattingMode="{TemplateBinding TextOptions.TextFormattingMode}"
                                    TextOptions.TextRenderingMode="{TemplateBinding TextOptions.TextRenderingMode}"
                                    RenderOptions.ClearTypeHint="{TemplateBinding RenderOptions.ClearTypeHint}"
                                    Style="{TemplateBinding params:TabItem.HeaderStyle}"
                                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=FontSize, Mode=OneWay, Converter={StaticResource IsGreaterThanConverter}, ConverterParameter=18}">
                <Setter Property="TextOptions.TextFormattingMode" Value="Ideal"/>
            </DataTrigger>
            <Trigger Property="IsSelected" Value="True">
                <Setter Property="params:TabControl.IndicatorBrush" Value="{StaticResource AccentBrush}"/>
            </Trigger>
        </Style.Triggers>        
    </Style>

</ResourceDictionary>